
using UnityGameFramework.Runtime;

namespace StarForce.Hotfix
{
    /// <summary>
    /// 热更新层UGUI界面
    /// </summary>
    public class HotfixUGuiForm
    {
        /// <summary>
        /// 主工程的界面逻辑脚本
        /// </summary>
        public StarForce.HotfixUGuiForm UIFormLogic
        {
            get;
            private set;
        }

        /// <summary>
        /// 界面初始化
        /// </summary>
        public virtual void OnInit(StarForce.HotfixUGuiForm uiFormLogic,object userdata)
        {
            UIFormLogic = uiFormLogic;
//            m_ModelView = modelView;
        }

        /// <summary>
        /// 界面打开
        /// </summary>
        public virtual void OnOpen(object userdata)
        {
            HotfixGameEntry.Event.Subscribe(CloseUIFormEventArgs.EventId, OpenUIPageSuccess);
        }

        /// <summary>
        /// 界面关闭
        /// </summary>
        public virtual void OnClose(bool isShutdown,object userData)
        {
            HotfixGameEntry.Event.Unsubscribe(CloseUIFormEventArgs.EventId, OpenUIPageSuccess);
        }
        
        private void OpenUIPageSuccess(object sender, HotfixGameEventArgs e)
        {
            CloseUIFormEventArgs ne = e as CloseUIFormEventArgs;
            if (ne == null)
            {
                return;
            }
            
            Log.Info(ne.Type);
            Log.Info(GetType());
            
            
            if (ne.Type == GetType())
            {
                Close();
            }

        }

        /// <summary>
        /// 界面暂停
        /// </summary>
        public virtual void OnPause()
        {

        }

        /// <summary>
        /// 界面暂停恢复
        /// </summary>
        public virtual void OnResume(object userdata)
        {

        }

        /// <summary>
        /// 界面遮挡
        /// </summary>
        public virtual void OnCover(object userdata)
        {

        }

        /// <summary>
        /// 界面遮挡恢复
        /// </summary>
        public virtual void OnReveal()
        {

        }

        /// <summary>
        /// 界面激活
        /// </summary>
        public virtual void OnRefocus(object userData)
        {

        }

        /// <summary>
        /// 界面轮询
        /// </summary>
        public virtual void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {

        }

        /// <summary>
        /// 界面深度改变
        /// </summary>
        public virtual void OnDepthChanged(int uiGroupDepth, int depthInUIGroup)
        {

        }
        
        public virtual void Close()
        {
            UIFormLogic.Close();
        }
    }
}

